﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace mqtt
{
    class Program
    {
        static void Main(string[] args)
        {
            Run(() =>
            {
                MqttHelper.Start();

            }, () =>
            {
                MqttHelper.Stop();
            });

        }

        static void Run(Action start, Action stop)
        {
            var exitEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                exitEvent.Set();
            };

            start();
            Console.WriteLine("Application Start. Press Ctrl+C to shut down.");
            exitEvent.WaitOne();
            exitEvent.Dispose();
            stop();
            Console.WriteLine("Application Stop");
        }

    }
}

//dotnet *.dll
//dotnet *.dll &
//jobs  
//fg 1
//fg %1


//nohup dotnet *.dll
//nohup dotnet *.dll &

//ps -ef
//ps -aux
//kill -9 pid

//systemctrl stop filewalld


//https://www.cnblogs.com/heqiuyong/p/10460150.html

//1、开放端口

//firewall-cmd --zone=public --add-port=5672/tcp --permanent   # 开放5672端口

//firewall-cmd --zone=public --remove-port=5672/tcp --permanent  #关闭5672端口

//firewall-cmd --reload   # 配置立即生效

//2、查看防火墙所有开放的端口

//firewall-cmd --zone=public --list-ports


//3.、关闭防火墙

//如果要开放的端口太多，嫌麻烦，可以关闭防火墙，安全性自行评估

//systemctl stop firewalld.service

//systemctl start firewalld.service

//systemctl disable firewalld.service # 禁止firewall开机启动

//systemctl enable firewalld.service #开机启动

//systemctl is-enabled firewalld.service  #查看服务是否开机启动

//systemctl list-unit-files|grep enabled  #查看已启动的服务列表

//4、查看防火墙状态

// firewall-cmd --state


//5、查看监听的端口

//netstat -lnpt

//PS:centos7默认没有 netstat 命令，需要安装 net-tools 工具，yum install -y net-tools


//6、检查端口被哪个进程占用

//netstat -lnpt |grep 5672


//7、查看进程的详细信息

//ps 6832

//8、中止进程
//kill -9 6832

//==============================================================================
//开机启动
//etc/systemd/system  在此目录下新建文件 mqtt.service

//-------------------------------------------------------------

//[Unit]
//Description=mqtt

//[Service]
//Type=simple
//GuessMainPID=true
//WorkingDirectory=/home/mqtt
//StandardOutput =journal
//StandardError=journal
//ExecStart=/usr/bin/dotnet mqtt.dll
//Restart=always

//[Install]
//WantedBy=multi-user.target

//----------------------------------------------------

//systemctl enable mqtt.service
//systemctl start mqtt.service
//systemctl stop mqtt.service
//systemctl disable mqtt.service
